#region Import section

using System;
using System.IO;
using NUnit.Framework;
using SQLRunnerLib;
using SQLTests.Framework;
using SQLRunnerLib.Project;
using System.Linq;

#endregion

namespace SQLTests.Lib.Project
{
	/// <summary>
	/// Summary description for ProjectTests.
	/// </summary>
	public class ProjectTests:
		AbstractTest
	{
	    [Test]
		public void CreateProjectFile() 
        {
		    var projectFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"project.sqlrunner");
            Project.Serialize(projectFile);
            DeserializedProj = SQLProject.Deserialize(projectFile);
            Assert.IsTrue(DeserializedProj.Environments.Count == 1, "One environment was expected");
		}

        [Test]
        public void  CheckEnvironmentDetails()
        {
            CreateProjectFile();
            var env = DeserializedProj.Environments.First();
            Assert.IsTrue(env.ServerName.Equals("serverName"));
            Assert.IsTrue(env.IsSelected);
            Assert.IsTrue(env.PlaceHolders.Count == 0);
            Assert.IsTrue(env.Trusted);
        }

		#region fixtures
		private SQLProject Project;
	    private SQLProject DeserializedProj;
 
		[TestFixtureSetUp]
		protected override void SetUpFixtures()
		{
            Project = GetProject();
		}

	    public static SQLProject GetProject()
	    {
	        var project = new SQLProject();
	        project.Extensions.Add("sql");
	        var folder = new Folder
	                         {
	                             Path = @"C:\", 
	                             IncludeAllFiles = true, 
	                             IncludeAllSubFolders = false
	                         };
	        var subfolder = new Folder
	                            {
	                                Path = @"C:\Temp", 
	                                IncludeAllFiles = false, 
	                                IncludeAllSubFolders = false
	                            };
	        subfolder.Files.Add("test.sql");
	        var environment = new SQLRunnerLib.Environment
	                              {
	                                  Authentication = AuthenticationType.WindowsAuthentication,
	                                  DatabaseName = "dbName",
	                                  ServerName = "serverName",
	                                  SavePassword = false,
	                                  IsSelected = true,
	                                  Name = "test"
	                              };

	        folder.Folders.Add(subfolder);
	        project.Folders.Add(folder);
	        project.Environments.Add(environment);
	        return project;
	    }

	    #endregion
	}
}
